local skel = fk.CreateSkill {
  name = "efengqi__jiangchi",
}

Fk:loadTranslationTable{
  ["efengqi__jiangchi"] = "将驰",
  [":efengqi__jiangchi"] = "出牌阶段与你【杀】可使用次数共限两次，你可以摸一张牌。其他角色未使用【杀】的出牌阶段结束时，此技能下回合发动次数+1。",

  ["@efengqi__jiangchi"] = "将驰",
  ["#efengqi__jiangchi"] = "将驰:摸一张牌，令【杀】可使用次数-1",

  ["$efengqi__jiangchi1"] = "谨遵父训，不可逞匹夫之勇。",
  ["$efengqi__jiangchi2"] = "吾定当身先士卒，振魏武雄风！",
}

---@param player Player
local getJiangchiTimes = function (player)
  return 2 + player:getMark("efengqi__jiangchi-turn")
  - player:usedSkillTimes("efengqi__jiangchi", Player.HistoryPhase) - player:usedCardTimes("slash", Player.HistoryPhase)
end

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#efengqi__jiangchi",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  times = function (self, player)
    return getJiangchiTimes(player)
  end,
  can_use = function(self, player)
    return getJiangchiTimes(player) > 0
  end,
  on_use = function(self, room, effect)
    effect.from:drawCards(1, skel.name)
  end,
})

skel:addEffect("targetmod", {
  fix_times_func = function (self, player, skill, scope, card)
    if player:hasSkill(skel.name) and card and card.trueName == "slash" then
      return math.max(0, 2 + player:getMark("efengqi__jiangchi-turn") - player:usedSkillTimes(skel.name, Player.HistoryPhase))
    end
  end,
})

skel:addEffect(fk.EventPhaseEnd, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and not target.dead and target ~= player and target.phase == Player.Play then
      return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        return use.from == target and use.card.trueName == "slash"
      end, Player.HistoryPhase) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke(skel.name)
    player.room:addPlayerMark(player, "@efengqi__jiangchi")
  end,
})

skel:addEffect(fk.TurnStart, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@efengqi__jiangchi") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:addPlayerMark(player, "efengqi__jiangchi-turn", player:getMark("@efengqi__jiangchi"))
    player.room:setPlayerMark(player, "@efengqi__jiangchi", 0)
  end,
})


return skel
